package calao.contact.client;

import calao.client.Desktop;
import calao.client.Shortcut;
import calao.client.ui.Link;

import com.google.gwt.user.client.ui.VerticalPanel;
import com.google.gwt.user.client.ui.Widget;

public class ContactShortcuts 
extends Shortcut 
{
	
	final ContactMod mod;
	final ContactList contactList;
	
	ContactShortcuts(ContactMod mod)
	{
		super("calao.contact", mod.text.contacts(), mod.images.contactCard());
		this.mod = mod;
		contactList = new ContactList(mod);
	}
	
	public void init() 
	{
		if (mod.getDesktop().has(ContactService.MODIFY_CONTACTS)) {
			getMenuPanel().add(new Link(mod.text.newContact()) {
				public void onClick() {
					Desktop.getDesktop().setView(newCreateContactMenu(), mod.text.newContact());
				}
			});
		}
		getMenuPanel().add(new Link(mod.text.groups()) {
			public void onClick() {
				Desktop.getDesktop().setView(new GroupList(), mod.text.groups());
			}
		});
		setContent(contactList);
	}
	
	Widget newCreateContactMenu()
	{
		VerticalPanel panel = new VerticalPanel();
		panel.add(new Link(mod.text.newPerson()) {
			protected void onClick() {
				Desktop.getDesktop().setView(new ContactForm(new Person()), 
						mod.text.newContact());
			}
		});
		panel.add(new Link(mod.text.newOrganization()) {
			protected void onClick() {
				Desktop.getDesktop().setView(new ContactForm(new Organization()), 
						mod.text.newContact());
			}
		});
		return panel;
	}
	
}